package tarantula.reporter;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import tarantula.collector.ExecResults;
import tarantula.collector.TestDataCollector;
import tarantula.instrumenter.SourcePos;
import tarantula.util.Globals;
import junit.framework.TestCase;

public class ReporterTest extends TestCase {
	
	protected String testDataDir = "." + Globals.fileSep + "testdata";
	
	public void testBuggyStatements() {
		String tracedir = testDataDir + Globals.fileSep + "dataset1";
		Map<SourcePos, ExecResults> rankedNum = getRankedResults(tracedir);
		System.out.println("All the ranked statements based on suspiciousness: ");
		TestDataCollector.dumpCollectResult(rankedNum);
		
		//assertion
		List<SourcePos> list = new LinkedList<SourcePos>();
		for(SourcePos p : rankedNum.keySet()) {
			list.add(p);
		}
		assertEquals(6, list.size());
		assertEquals(7, list.get(0).lineNum);
		assertEquals(6, list.get(1).lineNum);
		assertEquals(1, list.get(2).lineNum);
		assertEquals(2, list.get(3).lineNum);
		assertEquals(3, list.get(4).lineNum);
		assertEquals(13, list.get(5).lineNum);
//		assertEquals(8, list.get(6).lineNum);
	}
	
	
	protected Map<SourcePos, ExecResults> getRankedResults(String traceDir) {
		return getRankedResults(traceDir, BuggyStatementReporter.output_num); //default num
	}
	
	protected Map<SourcePos, ExecResults> getRankedResults(String traceDir, int outputNum) {
		BuggyStatementReporter.output_num = outputNum;
		BuggyStatementReporter reporter = new BuggyStatementReporter(traceDir);
		Map<SourcePos, ExecResults> rankedResults = reporter.outputRankedBuggyStatement();
		return rankedResults;
	}
	
}